<template>
  <div class="resumeDetail">
    <div id="container">
      <div class="clearfix">
        <div class="content_l">
          <dl class="job_detail">
            <dt>
              <h1>
                <!-- <div>{{jobItem.company.title}}</div> -->
                {{resumeItem.worker.worker_nickname }}
              </h1>
            </dt>
            <dd class="job_request">
              <div
                v-if="resumeItem.worker.worker_experience > 0"
              >工作经验：{{resumeItem.worker.worker_experience}}年</div>
              <div v-else>工作经验：无经验</div>
              <div>目前状态：{{workerStates(resumeItem.worker.worker_demand_status-1)}}</div>
              <div>性别：{{genderArr(resumeItem.worker.worker_gender) }}</div>
              <div>最高学历：{{educationArr(resumeItem.worker.worker_education)}}</div>
              <div>出生日期：{{resumeItem.worker.worker_birthday}}</div>
            </dd>
            <dd class="job_bt">
              <h3 class="description">自我介绍</h3>
              <span class="job-text" v-html="resumeItem.worker.worker_introduction"></span>
            </dd>
            <dd class="job_bt" v-if="resumeItem.demandv2.length > 0">
              <h3 class="description">求职意向</h3>
              <div
                v-for="(item,index) in resumeItem.demandv2"
                :key="index"
                style="display: flex;justify-content: space-between;"
              >
                <span
                  class="job-text"
                  style="font-size:14px;font-weight:bold;width:60%;"
                  v-html="'期望工作：'+item.position_title+'<br>'+'期望地点：'+item.area_name+'<br>'+'工作类型：'+jobType(item.job_type)"
                ></span>
                <span
                  class="job-text"
                  style="float:right"
                  v-html="item.salary_min !=item.salary_max 
			   && ('期望薪资：'+item.salary_min + '-' + item.salary_max + '元/月')"
                ></span>
                <br />
              </div>
            </dd>
            <dd class="job_bt" v-if="resumeItem.experience.length > 0">
              <h3 class="description">工作经历</h3>
              <div v-for="(item,index) in resumeItem.experience" :key="index">
                <span
                  class="job-text"
                  style="font-size:14px;font-weight:bold"
                  v-html="item.company+'·'+item.position + '·' + transDate(item.date_entry)+'-'+ transDate(item.date_resignation)"
                ></span>
                <br />
                <span class="job-text" v-html="'工作内容:'+item.worker_description"></span>
                <br />
                <br />
              </div>
            </dd>
            <dd class="job_bt" v-else>
              <h3 class="description">工作经历</h3>
              <span class="job-text" v-html="'未填写工作经历'"></span>
            </dd>
            <div class="seeBlock">
              <a href="javascript:void(0)" @click="seePhone">
                <div class="seePhone">查看联系方式</div>
              </a>
            </div>
          </dl>
        </div>
        <div class="content_r">
          <dl class="job_company">
            <dd>
              <img :src="resumeItem.worker.worker_avatar" style="width:200px;" />
            </dd>
          </dl>
        </div>
      </div>
    </div>
    <!-- end #container -->
  </div>
</template>

<script>
import { Message } from "element-ui";
import { JobItem } from "~/api/worker/job.js";
import { ResumeDetail, BuyResume } from "~/api/allRequest.js";
import { getSalaryUnit, getJobTag } from "~/common/js/util.js";

export default {
  name: "positionDetail",
  data() {
    return {
      resumeItem: {},
      type: "worker_id"
    };
  },
  components: {},
  mounted() {
    if (this.$route.query.worker_id) {
      this.type = "worker_id";
      this.worker_id = this.$route.query.worker_id;
    } else if (this.$route.query.worker_apply_id) {
      this.type = "worker_apply_id";
      this.worker_apply_id = this.$route.query.worker_apply_id;
    }
    this.getResume();
  },
  methods: {
    async getResume() {
      let formItem = {};
      if (this.type == "worker_id") {
        formItem = {
          worker_id: this.worker_id
        };
      } else {
        formItem = {
          worker_apply_id: this.worker_apply_id
        };
      }
      let resumeItem = await ResumeDetail(formItem).catch(err => {
        Message.error("系统错误，请联系技术人员。" + err);
      });

      this.resumeItem = resumeItem;
    },
    seePhone() {
      if (this.resumeItem.isBuy) {
        this.$alert(
          this.resumeItem.worker.worker_nickname +
            "：" +
            this.resumeItem.worker.worker_phone
        );
      } else {
        if (this.resumeItem.member_right.free_resume_times > 0) {
          this.$confirm(
            `当前账户免费简历次数还有${this.resumeItem.member_right.free_resume_times}次，是否扣除1次查看该简历？`
          )
            .then(data => {
              this.buyAction();
            })
            .catch(err => {
              console.log(err);
            });
        } else {
          this.$confirm(`当前账户免费简历次数0，是否前往购买免费简历权益`)
            .then(data => {
              this.$router.push({ name: "equityMain" });
            })
            .catch(err => {
              console.log(err);
            });
        }
      }
    },
    buyAction() {
      let formItem = {};
      if (this.type == "worker_id") {
        formItem = { worker_id: this.worker_id };
      } else if (this.type == "worker_apply_id") {
        formItem = { worker_apply_id: this.worker_apply_id };
      }
      BuyResume(formItem)
        .then(result => {
          this.$message.success("购买成功");
          this.getResume();
          setInterval(() => {
            if (this.resumeItem.isBuy == 1) {
              this.$alert(
                this.resumeItem.worker.worker_nickname +
                  "：" +
                  this.resumeItem.worker.worker_phone
              );
              clearInterval();
            }
          }, 1000);
        })
        .catch(err => {
          console.log(err);
        });
    },
    salaryUnit(type) {
      return getSalaryUnit(type);
    },
    jobTag(index) {
      return getJobTag(index);
    },
    educationArr(index) {
      return [
        "未知",
        "小学",
        "初中",
        "中专",
        "高中",
        "大学专科",
        "大学本科",
        "硕士",
        "博士",
        "博士后",
        "其它"
      ][index];
    },
    genderArr(index) {
      return ["男女不限", "男", "女"][index];
    },
    transDate(str = "") {
      str = str.split("-");
      return str[1] + "月" + str[2].split(" ")[0] + "日";
    },
    jobType(index) {
      return ["全职", "兼职", "实习"][index];
    },
    companyScale(index) {
      return ["未知", "1-10人", "10-20人", "20-50人", "50-100人", "100人以上"][
        index
      ];
    },
    workerStates(index) {
      return ["在职_不考虑", "在职_考虑机会", "在职_月内到岗", "离职_随时到岗"][
        index
      ];
    }
  }
};
</script>

<style scoped lang="less">
@import "./../../../public/less/job_detail.less";
// @import "./../../../public/less/main.less";
.resumeDetail {
  .seeBlock {
    width: 100%;
    display: flex;
    justify-content: center;
  }
  .seePhone {
    background: #91cebe;
    width: 200px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    color: white;
    margin-top: 100px;
  }
}
</style>
